package com.campusify.service.impl;

import org.springframework.stereotype.Service;
import com.campusify.compents.PageResult;
import com.campusify.pojo.JobrecruitmentExample;
import com.campusify.pojo.JobrecruitmentExample.Criteria;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.campusify.mapper.JobrecruitmentMapper;
import com.campusify.pojo.Jobrecruitment;
import com.campusify.service.JobRecruitmentService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class JobRecruitmentServiceImpl implements JobRecruitmentService {

	@Autowired
	private JobrecruitmentMapper jobRecruitmentMapper;
	
	/**
	 * 查询全部
	 */
	@Override
	public List<Jobrecruitment> findAll() {
		return jobRecruitmentMapper.selectByExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);		
		Page<Jobrecruitment> page=   (Page<Jobrecruitment>) jobRecruitmentMapper.selectByExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(Jobrecruitment jobRecruitment) {
		jobRecruitmentMapper.insert(jobRecruitment);		
	}

	
	/**
	 * 修改
	 */
	@Override
	public void update(Jobrecruitment jobRecruitment){
		jobRecruitmentMapper.updateByPrimaryKey(jobRecruitment);
	}	
	
	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	@Override
	public Jobrecruitment findOne(Integer jobID){
		return jobRecruitmentMapper.selectByPrimaryKey(jobID);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Integer[] jobIDs) {
		for(Integer jobID:jobIDs){
			jobRecruitmentMapper.deleteByPrimaryKey(jobID);
		}		
	}
	
	
		@Override
	public PageResult findPage(Jobrecruitment jobRecruitment, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		
		JobrecruitmentExample example=new JobrecruitmentExample();
		Criteria criteria = example.createCriteria();
		
		if(jobRecruitment!=null){			
						if(jobRecruitment.getPositionname()!=null && jobRecruitment.getPositionname().length()>0){
				criteria.andPositionnameLike("%"+jobRecruitment.getPositionname()+"%");
			}			if(jobRecruitment.getDescription()!=null && jobRecruitment.getDescription().length()>0){
				criteria.andDescriptionLike("%"+jobRecruitment.getDescription()+"%");
			}			if(jobRecruitment.getPublishtime()!=null && jobRecruitment.getPublishtime().length()>0){
				criteria.andPublishtimeLike("%"+jobRecruitment.getPublishtime()+"%");
			}			if(jobRecruitment.getPhone()!=null && jobRecruitment.getPhone().length()>0){
				criteria.andPhoneLike("%"+jobRecruitment.getPhone()+"%");
			}	
		}
		
		Page<Jobrecruitment> page= (Page<Jobrecruitment>)jobRecruitmentMapper.selectByExample(example);		
		return new PageResult(page.getTotal(), page.getResult());
	}
	
}
